Test: fix unimplemented device export test#67
Merged
mstimberg merged 6 commits intobrian-team:masterfrom Mar 26, 2026
Merged
Conversation
mstimberg
requested changes
Mar 17, 2026
Member
mstimberg
left a comment
There was a problem hiding this comment.
Thanks, good catch! I left two minor comments in the review.
| run(10 * ms) | ||
| run(1*ms) | ||
|
|
||
| from brian2.core.base import BrianObject |
Member
There was a problem hiding this comment.
Could you move this import to the top of the file?
| _ = PoissonInput(G, 'g', 1, 1 * Hz, 1) | ||
| # with pytest.raises(NotImplementedError): | ||
| run(10 * ms) | ||
| run(1*ms) |
Member
There was a problem hiding this comment.
Could you remove the lines above – those are not actually tested here (for PoissonInput, you needed a NeuronGroup, but here you don't need anything else).
Contributor
Author
|
@mstimberg Thanks for the review, Looking into it. |
c0e9c85 to
9344604
Compare
Contributor
Author
|
Hey @mstimberg, I’ve updated the PR based on the review comments and also revised the PR description to reflect the changes more clearly. Please take a look when you get a chance and let me know what you think. |
mstimberg
requested changes
Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a broken unit test for unsupported export objects and resolves NumPy 2.x / Python 3.13 compatibility issues caused by stricter array-to-scalar conversion rules.
Changes
Fix broken unit test for unsupported export objects
The test_ExportDevice_unsupported test was meant to check that the exporter raises a NotImplementedError when it sees a Brian2 object it does not support.
The test was broken for two reasons:
• It used PoissonInput as the unsupported object, but PoissonInput is actually supported by the exporter.
• The pytest.raises(NotImplementedError) block had been commented out, so the test was no longer checking the expected failure.
This PR fixes the test by:
• replacing PoissonInput with a minimal custom class, UnsupportedObject, that directly subclasses BrianObject
• re-enabling the pytest.raises(NotImplementedError) assertion
• removing old setup code that was only needed for PoissonInput, including the NeuronGroup, equation string, and run(1*ms) call
• moving the BrianObject import to the top of the file to follow normal Python style
Since UnsupportedObject has no exporter implementation, running a Network containing it with the exporter device now correctly raises NotImplementedError. The test now passes and checks the intended behavior properly.
Fix failures on NumPy 2.x / Python 3.13
NumPy 2.x is stricter about converting arrays into scalar values. A few places in the code were relying on older NumPy behavior where a 1-element array could be treated like a plain number. These cases now fail in CI on Python 3.13.
test_baseexport.py — test_spikegenerator
SpikeGeneratorGroup stores spike times as a 1D array. The test was calling float() directly on this array when comparing it to the original input.
In NumPy 2.x, float() only accepts 0D arrays, so this raises a TypeError.
Fixed by extracting the first element with [0] on both sides before calling float().
mdexport/expander.py — expand_initializer
When a variable is initialized for only part of a neuron group, for example group.v[0:5] = ..., the index is stored as a NumPy integer array.
The code was comparing this array directly to the strings 'True' and 'False' using == inside an or expression. In NumPy, this returns an array of booleans, not a single boolean value. Using that in Python or raises:
ValueError: The truth value of an array with more than one element is ambiguous
Fixed by checking isinstance(index, str) before doing the string comparisons, so they only run when index is actually a string.
plotting/morphology.py — _plot_morphology2D
After calling generate_coordinates(), Brian2 returns Soma.x, Soma.y, and Soma.diameter as 1-element 1D arrays instead of plain scalar values.
Matplotlib’s Circle eventually passes these values into an internal affine transform that requires real Python floats, which causes a ValueError.
Fixed by applying np.squeeze() before float(). This converts a 1-element 1D array into a 0D array, which float() can safely convert to a scalar.
Result
• restores a meaningful unit test for unsupported export objects
• fixes CI failures with NumPy 2.x
• improves compatibility with Python 3.13